package com.ict.txmsv2.schedule;

import com.ict.txmsv2.mapper.CheckUserMapper;
import com.ict.txmsv2.model.CheckUser;
import com.ict.txmsv2.services.EmailSendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import java.util.List;

/**
 * @author linzzz
 * @desc ...
 * @date 2020-12-16
 */
@Component
public class EmailSchedule {

    @Autowired
    CheckUserMapper checkUserMapper;

    @Autowired
    EmailSendService sendService;

    @Scheduled(cron = "0 0/1 * * * ?")
    public void SendEmail() throws MessagingException {
        List<CheckUser> checkUsers = checkUserMapper.selectEmailTo();
        for (CheckUser checkUser : checkUsers) {
            sendService.sendThymeleafMail(checkUser);
            checkUserMapper.deleteByPrimaryKey(checkUser.getId());
        }
    }
}
